package com.example.administrator.runbook.fragments.community;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.administrator.runbook.R;
import com.example.administrator.runbook.fragments.CommonFragment;
import com.example.administrator.runbook.fragments.community.activity.TrendsActivity;
import com.example.administrator.runbook.fragments.community.adapter.TrendsListAdapter;
import com.example.administrator.runbook.fragments.community.model.Trends;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class CommunityFragment extends CommonFragment implements AdapterView.OnItemClickListener {


    private ListView listView;
    private List<Trends> list;
    private TrendsListAdapter adapter;

    public CommunityFragment() {
        // Required empty public constructor
    }

    public String getTitle() {
        return "社区";
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_community, container, false);
        listView = (ListView) view.findViewById(R.id.list_view_fragment_community);
        initData();
        initListener();
        return view;
    }

    private void initData() {
        list = new ArrayList<>();
        list.add(new Trends(R.mipmap.ic_trends, "动态"));
        list.add(new Trends("公共社区", 1));
        list.add(new Trends(R.mipmap.discuss_section, "综合讨论区"));
        list.add(new Trends(R.mipmap.comment_section, "书评区"));
        list.add(new Trends(R.mipmap.helper_section, "书荒互助区"));
        list.add(new Trends(R.mipmap.new_yuanchuang, "原创区"));
        list.add(new Trends(R.mipmap.girl_section, "女生区"));
        adapter = new TrendsListAdapter(getContext(), list);
        listView.setAdapter(adapter);
    }

    private void initListener() {
        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (position == 0) {
            Intent intent = new Intent(getContext(), TrendsActivity.class);
            startActivity(intent);
        }
    }
}
